package com.tenement.controller.homepage;

import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.tenement.base.constants.SysmConstants.state;
import com.tenement.mybatis.entity.User;

/**
 * 查询首页、信息发布页面、房屋详情页面、用户个人信息、个人空间页面
 * 
 * @author wk
 *
 */
@Controller
public class TopBarController {

	private static final Log logger = LogFactory.getLog(TopBarController.class);

	/**
	 * 获取session中的用户信息
	 * 
	 * @param session
	 * @return
	 */
	@RequestMapping(value = "/topBarOper.action")
	public @ResponseBody User topBarOper(HttpSession session) {
		User user = (User) session.getAttribute("USERMSGKEY");
		logger.info("【获取session中保存的user信息为空】" + (user == null));
		return user;
	}

	/**
	 * 退出，清除session
	 * 
	 * @param session
	 */
	@RequestMapping(value = "/logout.action")
	public @ResponseBody String logout(HttpSession session, @RequestBody String uNickname) {
		logger.info("【-用户" + uNickname + " 退出登录-】");
		session.removeAttribute("USERMSGKEY");
		return state.Success;
	}

}
